/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Example_07_Map.java]
 * Creation Date        [01-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_06_collections;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 集合框架java.util.Map
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_07_Map {

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		Map<Integer, String> map = new HashMap<Integer, String>();
		map.put(1, "One");
		map.put(2, "Two");
		map.put(3, "Three");

		// 迭代Map的两种方式
		Set<Integer> keySet = map.keySet();
		for (Iterator<Integer> iterator = keySet.iterator(); iterator.hasNext();) {
			Integer key = iterator.next();
			System.out.println("key ---> " + key + " value ---> "
					+ map.get(key));
		}

		Set<Map.Entry<Integer, String>> entries = map.entrySet();
		for (Map.Entry<Integer, String> entry : entries) {
			System.out.println("key ---> " + entry.getKey() + " value ---> "
					+ entry.getValue());
		}
	}

}
